{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "Using TensorFlow backend.\n"
     ]
    }
   ],
   "source": [
    "import numpy as np\n",
    "import json\n",
    "from keras.models import Model\n",
    "from keras.layers import Input\n",
    "from keras.layers.convolutional import Conv2D\n",
    "from keras.layers.pooling import MaxPooling2D, AveragePooling2D\n",
    "from keras.layers.normalization import BatchNormalization\n",
    "from keras import backend as K"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "def format_decimal(arr, places=8):\n",
    "    return [round(x * 10**places) / 10**places for x in arr]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### pipeline 6"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'input': {'shape': [24, 24, 2], 'data': [-0.88950621, 0.99521031, 0.47220426, 0.83892263, 0.34986091, -0.5127479, -0.85907429, 0.77944075, 0.19029341, 0.32220462, -0.21424713, -0.58489316, -0.75635827, 0.16071649, 0.10357716, 0.79782815, 0.72936078, -0.11674869, -0.17469282, 0.68982988, 0.54069298, 0.19767543, 0.82344286, -0.30560278, -0.28262038, -0.55290746, 0.41984862, 0.52038618, 0.29797074, 0.07653908, -0.05827217, -0.90281756, -0.6175877, 0.81560005, -0.27364955, -0.19942883, -0.01045536, 0.43508835, 0.39663825, 0.0598119, 0.15069681, -0.15147903, -0.01250035, -0.96369686, 0.55881727, -0.47242253, 0.7873261, -0.49953538, 0.00465018, -0.85377254, -0.29237312, -0.77330106, 0.46087118, 0.86567314, -0.08677915, -0.15856687, 0.69694185, -0.12566426, 0.06150914, 0.16531291, 0.46107044, 0.57508214, 0.02202647, 0.79850048, -0.41114344, -0.37490905, -0.31410755, 0.38383427, -0.9513819, 0.72219543, -0.43342095, 0.57434578, 0.97363903, -0.24306075, 0.47442068, -0.28541586, 0.71800542, 0.37571873, -0.00707913, 0.87936439, -0.08503837, -0.08943233, -0.28830674, 0.06704988, -0.36581162, -0.42678248, 0.13421105, 0.26608374, -0.79454339, 0.32088422, -0.70366175, -0.3472073, -0.60367578, 0.28946061, 0.06566343, 0.47498335, 0.66982937, 0.10694245, 0.7223306, -0.53145503, 0.8725357, -0.5834744, -0.39273777, -0.4557847, 0.71248831, -0.8979854, -0.60859533, -0.79858299, -0.33105317, -0.72253692, -0.94349074, 0.14962451, 0.20664417, -0.82110602, -0.25950858, 0.26504955, -0.76784025, 0.20400723, 0.89056582, -0.69043449, -0.27230832, 0.38688699, -0.84463183, -0.42709231, 0.54517843, 0.32432212, 0.53924057, 0.074527, -0.48907789, 0.08152135, 0.18356808, -0.73186215, 0.61565657, 0.44783808, 0.8750013, 0.98092491, -0.08482061, 0.27245021, 0.20242128, -0.7508122, -0.62895582, 0.98902609, 0.68916563, -0.80492836, -0.51671088, -0.62577336, -0.13816396, -0.27896915, -0.95705494, -0.1735586, -0.27543564, 0.44316691, 0.07877056, 0.84099898, 0.41335368, -0.10505639, 0.67952742, -0.63796377, 0.42584284, -0.67317177, -0.60579903, 0.23588383, 0.97682756, -0.84540701, 0.56057244, 0.19742975, 0.76796445, 0.01176248, -0.68886296, 0.12806775, -0.10344794, -0.89393581, 0.06799078, -0.14342641, -0.35672137, -0.52745654, -0.42835196, -0.09506711, 0.8683898, -0.17496744, 0.99424214, -0.93467497, -0.44978292, -0.88968775, -0.46892419, -0.15003813, -0.11536557, -0.53637892, 0.57675294, -0.52185626, -0.94722015, 0.67357189, 0.70463798, -0.71165826, 0.79885935, -0.48472964, 0.12498421, -0.49341898, 0.97988543, -0.08899378, 0.34934313, -0.33151862, -0.34944443, -0.24136357, -0.32526108, 0.19379593, -0.98345811, -0.69330511, -0.50820355, 0.12206785, -0.7613113, -0.34384566, -0.59291172, -0.69972346, -0.63931371, 0.02558583, 0.76267865, -0.1349497, -0.30494759, -0.85392524, 0.83512745, 0.65273403, -0.2009159, -0.4812853, -0.92845849, 0.09385077, -0.26697377, 0.65413566, -0.81147053, -0.64044239, 0.39738745, -0.09069432, -0.8049311, -0.1684389, -0.43602405, -0.99841694, 0.49267958, -0.10345301, -0.55049136, -0.48215662, 0.20334699, 0.75650709, -0.95489834, 0.76375646, 0.55349481, -0.97394328, 0.76784265, 0.48157854, -0.89630211, 0.58293853, 0.88545822, 0.6281103, 0.19949991, 0.63406256, 0.60999904, 0.63062277, 0.08817743, 0.99334128, -0.17880477, -0.15904011, 0.3451823, 0.43263907, 0.10057684, 0.7140646, -0.01850946, 0.44232858, -0.83447828, 0.51469528, -0.85068362, 0.42429479, -0.88677406, 0.85422029, 0.55772703, -0.18649934, 0.07557876, 0.73719647, 0.1070275, 0.61329102, 0.26764682, 0.27149182, 0.01663095, -0.76453738, -0.23820997, 0.09160678, 0.00768153, 0.3135177, 0.44789485, 0.03014532, 0.34827625, 0.38096166, 0.98927285, 0.24128545, -0.38207957, -0.93990438, -0.76091354, 0.72889212, 0.06780124, 0.32747501, -0.94978638, 0.24715475, 0.56393723, 0.40031589, -0.08485182, 0.77038823, -0.8633741, 0.29813954, 0.56612619, 0.08947527, -0.00513656, -0.97543614, -0.54095516, -0.09682112, 0.04380206, 0.16400457, 0.4466866, -0.62055515, -0.67595911, -0.98603496, -0.48104705, -0.65798638, -0.72318436, 0.42539792, -0.26382264, -0.90206793, 0.29044426, -0.9935992, -0.02678596, 0.97260965, -0.93126058, -0.26419602, 0.87461564, -0.1674289, -0.63816689, -0.87171578, -0.34911604, -0.38956909, -0.15602384, -0.95576025, -0.52628635, 0.20206417, 0.06742676, -0.28205617, -0.83237907, 0.43165598, 0.619812, 0.67673049, 0.63593379, 0.45188426, 0.33086643, -0.5365239, -0.04436076, -0.94473375, -0.62504068, -0.69240193, 0.48168498, 0.25964948, -0.85042753, -0.62660728, -0.27909742, 0.18385915, 0.70469776, -0.13238771, -0.29979701, 0.8126988, -0.25648017, -0.18312613, -0.68426217, 0.39908263, -0.64357931, 0.26256826, -0.45996786, -0.01191499, 0.23877894, -0.20212765, 0.28208563, 0.97160499, 0.13784252, 0.34076187, -0.47881589, 0.96180868, -0.21278562, 0.32204033, -0.09937374, -0.80716764, 0.12965869, -0.01563218, -0.63020358, -0.95491021, 0.72141006, 0.77646844, 0.81985571, -0.94075873, 0.40552546, -0.04930695, -0.44426819, -0.75941741, -0.97909619, -0.34430453, 0.03955225, -0.15834689, 0.79886012, 0.23492032, 0.96357477, 0.8538565, 0.75448395, 0.35895143, 0.2016628, 0.85568905, 0.59187326, 0.08305423, 0.936377, 0.10306251, 0.94749065, 0.26572484, 0.02998526, -0.59880802, -0.50711101, 0.19665359, 0.80785778, -0.79355138, 0.68375433, -0.02358549, -0.96909334, -0.6640443, 0.2572022, -0.69182873, -0.22044484, -0.34967131, -0.67067827, -0.90731979, 0.56206559, 0.55165846, -0.78192932, 0.74671098, -0.82914845, -0.69023337, -0.99900925, 0.68035276, -0.44275869, -0.53791104, 0.30291451, -0.03320074, -0.20353042, 0.83077551, 0.42475977, 0.54311138, 0.50686966, 0.18766329, -0.88168864, -0.01425633, -0.15646685, -0.80640868, 0.20522415, 0.26254294, -0.68171969, -0.92905482, 0.09349134, 0.61279644, -0.2677821, 0.33898405, -0.39872978, 0.4925963, -0.18689255, -0.8896375, 0.10405476, -0.17687107, 0.94160132, 0.1474691, -0.4265673, 0.39270516, 0.73218059, -0.09035792, 0.84902812, -0.97740778, -0.30162209, 0.75661706, 0.69499742, 0.91390736, 0.76972891, 0.39434305, 0.74512567, -0.41671388, -0.06737003, -0.96470279, 0.80983617, -0.486504, 0.29344057, -0.84610415, 0.20041493, 0.56554072, 0.3782142, 0.87067302, -0.37730395, 0.296384, -0.91809203, 0.56573587, -0.65817475, 0.04944097, 0.86776011, 0.55041799, 0.95384801, 0.6912756, -0.27101552, -0.83687809, -0.06652128, -0.41244039, 0.77585977, -0.89774238, -0.86557517, -0.92603294, -0.78908442, 0.70188613, 0.47603789, 0.23707049, 0.12204784, 0.13267805, -0.7522298, -0.84955986, 0.56704891, -0.32666543, 0.35365088, -0.05706375, 0.33255694, -0.90042032, 0.11043987, -0.47956184, 0.13740881, -0.3325451, 0.55772592, -0.77080725, -0.76217544, -0.6540045, -0.74272361, -0.46511758, 0.96081884, -0.76020768, 0.22338583, -0.315034, 0.81220518, -0.46759517, -0.30924347, -0.76389463, -0.16332112, 0.19493873, -0.23349688, -0.64005446, -0.24807964, -0.75488094, 0.594997, -0.13294408, -0.16184345, 0.46664544, 0.28492665, -0.48173174, 0.27591608, 0.91956601, 0.71051892, -0.94420543, -0.93829207, -0.04902679, 0.99925336, 0.08216751, 0.50901436, 0.164056, -0.53234868, 0.87702766, -0.76464679, -0.6789047, -0.84213324, 0.22708644, -0.69580283, 0.34519432, -0.76043278, -0.92947986, -0.91438438, -0.39275128, 0.79878441, 0.39177056, -0.50446256, -0.55583517, -0.29822747, -0.73898243, -0.77218448, 0.7836893, -0.68827803, -0.47096458, -0.20099454, 0.50967016, -0.10075344, -0.36748985, 0.35092403, -0.02665806, 0.7926011, 0.16268057, -0.22920703, 0.12947074, 0.75585585, 0.48384659, 0.3155264, 0.24357485, -0.76919584, 0.2313309, 0.97511943, 0.66880663, 0.46947685, 0.46416913, 0.53312873, 0.32838841, 0.58096114, -0.34661006, 0.54692834, -0.19155585, -0.28558763, 0.5468874, 0.21197428, 0.59839316, 0.07017417, -0.53054226, 0.39623737, -0.10780049, -0.57580718, -0.19143966, -0.46187434, 0.48210877, -0.67266503, -0.62373363, 0.88078582, 0.25271925, -0.13629392, 0.67118874, 0.43897613, 0.90991993, -0.46421934, -0.76133591, -0.27056841, -0.31266004, -0.88757451, -0.92741024, -0.67279043, -0.55343485, 0.36471091, -0.80511098, 0.07356055, -0.09819234, 0.17151514, -0.38056299, 0.6617745, 0.59424022, 0.15708384, -0.59761604, 0.20145331, -0.19669854, -0.51623572, 0.79572904, -0.213893, -0.0060244, -0.19446322, -0.3597347, 0.91026806, -0.57700658, 0.61471911, -0.71632559, 0.0632977, 0.78442432, 0.07194124, 0.72261237, -0.55370125, 0.17009426, -0.65889156, 0.12905915, 0.87455891, 0.4002228, 0.47830531, -0.58194425, -0.44240091, -0.54323634, -0.07027419, -0.20219478, -0.16452552, -0.39532757, -0.45288351, 0.74783033, -0.27944935, -0.77794965, -0.55187504, -0.87288128, -0.66699233, 0.4927878, -0.64841674, 0.15741852, -0.84542612, -0.60818166, -0.34074559, -0.09481959, -0.89065846, -0.35538066, 0.76460893, -0.91398389, -0.71186242, 0.98739192, -0.4334738, 0.50228247, 0.76877712, 0.14817506, 0.80683842, 0.39399283, 0.39905861, -0.35853577, -0.30047261, -0.54229363, -0.53392614, -0.17721314, -0.96178979, 0.91782319, -0.12649757, -0.82393245, 0.92703757, 0.23206971, 0.26820876, -0.8552579, -0.74109442, -0.44691029, -0.33480101, -0.96183824, 0.99601558, 0.26857712, -0.39015733, 0.9488639, 0.40082814, 0.87175089, -0.86978498, 0.13553756, -0.79872059, 0.92324, -0.78249366, 0.18884087, 0.57505295, -0.14877221, -0.955466, 0.85354904, -0.61905298, -0.34204444, 0.50317168, -0.27878916, 0.66070698, -0.881158, -0.56506175, -0.91885035, -0.09905422, 0.30390189, 0.0296154, 0.14433654, -0.56272413, 0.13362237, 0.3894905, -0.69707914, 0.39717003, -0.36456762, -0.86598526, 0.67948581, -0.36601359, 0.30795871, -0.37823919, 0.99552134, -0.54876806, -0.22095879, 0.07701033, -0.37503862, 0.31951001, 0.24052435, 0.42313035, -0.65605922, -0.62022794, 0.03858797, 0.81067173, 0.65797744, -0.11563709, 0.22620822, -0.25440804, 0.8528855, 0.29342642, 0.16410535, -0.43278201, 0.73581192, -0.32809067, -0.45906877, 0.94035078, 0.04365174, -0.42238374, -0.45806932, 0.18021639, 0.5603409, 0.14945397, 0.34356409, -0.07890094, -0.31684598, 0.03113528, 0.28353685, -0.9998031, 0.81492452, -0.21933026, 0.16377558, 0.93985199, 0.38496763, -0.92123862, 0.49031848, -0.83648659, 0.42208386, -0.8866986, 0.30381119, -0.71197056, 0.40938531, 0.83260093, 0.14079077, 0.85066747, 0.44865674, -0.82695549, 0.56182258, -0.28050314, 0.26655491, 0.93252096, -0.94044848, 0.95389736, 0.71358903, -0.21684335, 0.00931532, 0.5962938, -0.16573116, 0.52456815, 0.23223057, 0.42304367, 0.82136785, 0.42535647, -0.42949777, -0.50060354, 0.39898326, 0.41748716, -0.43766241, -0.46716902, 0.1095415, -0.99650809, 0.15420163, 0.95871987, -0.62845336, -0.52000939, -0.58569085, 0.80950106, 0.85114541, -0.99419435, -0.41703132, 0.25986003, 0.69254611, 0.3420074, -0.43847475, 0.07291488, 0.96114598, 0.51628608, -0.23238569, -0.9858239, -0.68480291, -0.69329794, -0.04077758, -0.5545379, -0.26041545, -0.03422987, -0.16791568, -0.16116591, 0.24609933, -0.17586883, 0.34447022, -0.00465405, 0.43648061, 0.03679383, -0.84178151, -0.3618972, -0.63172485, -0.64499916, -0.18756862, 0.66965877, 0.72567011, 0.24577473, 0.24590808, -0.21133701, -0.23986062, 0.96857999, -0.4115687, -0.94891573, 0.04399376, 0.09770578, 0.95677255, 0.91256606, 0.76469833, 0.34794067, -0.59480937, -0.46387475, 0.3884033, 0.26238783, 0.96632193, 0.57455732, 0.00205246, -0.89972644, -0.61708892, -0.55923618, 0.95205727, -0.86636076, 0.23476855, -0.07845189, 0.48032193, 0.00345417, 0.07724318, 0.40900055, 0.43856239, 0.29378879, 0.02296568, 0.10499401, -0.20937408, -0.81620319, -0.82321699, 0.51698131, 0.40449392, -0.85709825, -0.52266201, 0.07510924, 0.89533629, 0.81440272, 0.0678294, 0.66544349, -0.05166513, 0.40315368, 0.68939723, -0.12138746, 0.38732306, 0.19784988, 0.67309298, -0.06421169, 0.48973837, 0.16232217, -0.94140249, -0.51739518, 0.80559417, 0.65524302, -0.5947297, 0.85686512, -0.89138927, 0.27125315, -0.2063045, -0.32805867, 0.84513478, -0.35996099, -0.72658601, 0.58316903, -0.9549844, 0.93468619, 0.41441149, 0.74550356, -0.51545568, 0.09852525, -0.26671785, 0.67472757, 0.94785836, 0.78243276, -0.96433796, 0.86331156, -0.35524301, -0.87304261, -0.08213053, 0.32127295, -0.19032517, 0.05816707, -0.82277581, -0.8653357, -0.53143015, -0.32260383, 0.99449576, 0.93631106, 0.02756969, 0.24260883, -0.92051001, -0.25334203, -0.64815615, -0.88613202, 0.29547595, 0.28714922, -0.66853622, -0.18390677, -0.34471214, 0.45478414, -0.16524319, -0.03177634, 0.50650774, 0.49699783, -0.25879803, 0.57223646, -0.47037056, 0.13747397, 0.60784719, -0.91538782, -0.17160585, 0.67816507, -0.52698592, 0.59854775, -0.94678616, 0.90368484, -0.82484391, -0.53900356, -0.98687009, 0.78215702, -0.2824592, -0.81947628, 0.79586689, -0.37413787, -0.51369174, -0.31620987, 0.5624666, -0.594235, -0.869023, 0.05964141, 0.78502933, 0.63250344, -0.48025138, -0.75717393, -0.78075139, 0.83936933, 0.11323401, 0.84546199, 0.3206356, -0.7814775, -0.46916813, 0.97814359, 0.95717072, -0.88838478, -0.33480427, -0.4584182, -0.43157626, 0.87829677, 0.00818843, 0.48482675, -0.38274232, -0.0104487, -0.03022314, -0.44509217, -0.41818586, 0.9756824, -0.28225641, -0.50667096, 0.47627681, -0.55861253, -0.76607548, -0.72825052, 0.25273316, 0.87626842, -0.17031307, -0.69650602, 0.1555758, -0.65309194, -0.92024629, -0.8057603, 0.90739512, -0.04114562, -0.02884868, -0.78513725, 0.45421264, 0.61713022, -0.93802056, -0.34065532, 0.3169491, 0.05021934, -0.5109612, 0.92442415, -0.49370615, -0.1666157, 0.86717486, -0.06956588, -0.14393108, 0.50619289, 0.75656728, -0.07075803, 0.09012038, 0.22276767, 0.8797013, -0.32025584, 0.57903421, 0.2531355, 0.54346883, 0.54367983, -0.08186628, -0.40844824, -0.30021168, -0.39194174, -0.0973594, -0.86565582, 0.74596282, 0.21575485, -0.95286169, -0.18555242, 0.80166359, 0.64184879, -0.99932435, -0.69007736, -0.12126306, -0.49444786, -0.5852561, 0.74566516, -0.78541657, 0.96108745, 0.34859416, -0.3915861, 0.48860855, 0.63090345, -0.11779111, 0.84851045, -0.39284451, -0.66248243, -0.09101458, -0.23578081, -0.08900836, -0.99644123, -0.21938702, -0.96366845, 0.44399658, -0.42668621, 0.49488307, -0.49043143, 0.91218102, -0.06495779, -0.65212268, -0.88594822, -0.07137017, -0.52851964, -0.11606665, -0.06710445, -0.85456165, -0.61960851, -0.74528244, 0.10802951, 0.55762095, 0.1802158, 0.9896131, -0.43150135, 0.43742264, -0.69476718, 0.4450504, 0.21680862, 0.82253497, 0.8991287, 0.86636063, -0.28430695, 0.62452033, -0.21045374, 0.29792918, 0.97284342, 0.27654157]}, 'weights': [{'shape': [3, 3, 2, 5], 'data': [-0.44475311, 0.49760516, 0.23610213, 0.41946131, 0.17493046, -0.25637395, -0.42953715, 0.38972037, 0.09514671, 0.16110231, -0.10712356, -0.29244658, -0.37817914, 0.08035825, 0.05178858, 0.39891407, 0.36468039, -0.05837434, -0.08734641, 0.34491494, 0.27034649, 0.09883771, 0.41172143, -0.15280139, -0.14131019, -0.27645373, 0.20992431, 0.26019309, 0.14898537, 0.03826954, -0.02913608, -0.45140878, -0.30879385, 0.40780002, -0.13682477, -0.09971441, -0.00522768, 0.21754417, 0.19831913, 0.02990595, 0.0753484, -0.07573951, -0.00625018, -0.48184843, 0.27940864, -0.23621127, 0.39366305, -0.24976769, 0.00232509, -0.42688627, -0.14618656, -0.38665053, 0.23043559, 0.43283657, -0.04338958, -0.07928344, 0.34847092, -0.06283213, 0.03075457, 0.08265645, 0.23053522, 0.28754107, 0.01101323, 0.39925024, -0.20557172, -0.18745452, -0.15705377, 0.19191714, -0.47569095, 0.36109771, -0.21671047, 0.28717289, 0.48681951, -0.12153037, 0.23721034, -0.14270793, 0.35900271, 0.18785936, -0.00353957, 0.43968219, -0.04251918, -0.04471617, -0.14415337, 0.03352494, -0.18290581, -0.21339124, 0.06710552, 0.13304187, -0.39727169, 0.16044211]}, {'shape': [5], 'data': [-0.08031645, 0.07633546, 0.22970436, -0.13126783, 0.37475751]}, {'shape': [5], 'data': [0.31115482, -0.46685926, -0.259036, 0.43030349, -0.08863987]}, {'shape': [5], 'data': [-0.24135733, -0.09916874, -0.16318507, -0.37525773, -0.01296121]}, {'shape': [5], 'data': [0.28643066, 0.36902768, -0.35207342, 0.09113127, 0.11871349]}, {'shape': [5], 'data': [0.3530826, 0.32966741, 0.26205467, 0.06034495, 0.42667279]}, {'shape': [3, 3, 5, 4], 'data': [-0.4589246, 0.49431824, -0.07972746, 0.11030469, 0.3915638, 0.40596725, -0.41710068, 0.31130824, -0.21239112, -0.23279866, -0.35721466, 0.31492211, 0.32237439, -0.23758679, -0.17205443, -0.06527541, -0.07036738, 0.43522514, 0.48676289, -0.32995835, 0.40002257, 0.28519954, 0.30333386, 0.17525979, 0.19241959, 0.34689939, 0.01886171, -0.27150874, -0.34919191, 0.14329576, -0.42756876, -0.44521741, -0.31567451, 0.43838377, 0.25076522, 0.26461714, -0.41926704, -0.29799478, -0.40271515, 0.27610409, 0.02049909, -0.4885194, 0.20949698, -0.02600276, 0.39801845, -0.48196943, -0.28095617, -0.18209355, -0.38028688, 0.17733372, -0.21243898, 0.02159542, 0.08452222, -0.30815158, 0.28475484, -0.27649554, -0.06899959, -0.18398888, 0.15293195, -0.43436197, -0.2220331, 0.13210244, -0.28256048, -0.30341859, 0.33732672, 0.10939452, -0.12388093, -0.36935003, 0.4514036, 0.37980069, -0.45480205, -0.23264685, 0.10376878, -0.14640269, 0.44328312, -0.26832785, 0.08396142, 0.1961791, 0.30823569, -0.13059966, -0.06638739, -0.06107255, -0.49705347, -0.17717804, -0.24556534, 0.48206225, 0.4053258, -0.48515236, 0.49830903, -0.41709031, 0.34631609, 0.12156763, 0.16576885, -0.4225028, 0.41600135, 0.27339715, 0.11663938, 0.42139073, 0.39479599, 0.00335356, 0.14105246, -0.01738759, -0.23897713, -0.38202586, -0.2981434, 0.07719996, 0.11555274, -0.10181579, 0.22744002, -0.12670202, -0.02451419, 0.47243682, -0.01693288, -0.19403654, 0.11103912, 0.15910501, 0.35172366, -0.49961262, -0.42150372, -0.39817782, 0.29297918, -0.26593107, -0.24448471, -0.41906567, 0.31676953, 0.23033546, 0.35932094, 0.34271207, -0.4426115, 0.31716062, 0.44736377, 0.37260121, -0.32680973, 0.1772833, -0.43158399, 0.16725921, -0.2609566, 0.25929571, 0.08553501, 0.46506566, -0.21325926, 0.48119716, -0.37593923, 0.3891873, -0.33116739, -0.27400662, 0.01794086, -0.47797519, -0.33347022, -0.34274725, 0.1093359, 0.37982905, -0.10733194, 0.30981961, -0.45847656, -0.22315049, -0.46384373, -0.48310256, -0.17469735, -0.36769831, 0.44980617, 0.41416403, 0.22037153, 0.30921601, -0.12018486, 0.41245311, -0.13567707, -0.47564547, -0.06180949, -0.21987977, -0.07574066, 0.39659119, -0.23410193, -0.11868224, 0.11112707, -0.43790447, 0.07561609, -0.05301346, -0.18743518, 0.24326622]}, {'shape': [4], 'data': [0.49638426, 0.32067412, 0.47819464, 0.14256451]}, {'shape': [4], 'data': [-0.12025937, 0.3357645, -0.37926303, 0.13390083]}, {'shape': [4], 'data': [0.15104293, 0.31587833, -0.24326722, 0.09347506]}, {'shape': [4], 'data': [-0.18751411, -0.42629415, 0.30691551, -0.40795206]}, {'shape': [4], 'data': [0.0343939, 0.29390896, 0.01414098, 0.12141513]}, {'shape': [3, 3, 4, 3], 'data': [0.39198737, 0.41735322, -0.25688922, 0.05344539, 0.14953325, -0.07534302, 0.02156402, 0.3948233, 0.0427305, -0.41601147, -0.03278211, 0.00014555, -0.27437335, -0.05017925, 0.40863693, 0.47735252, 0.15519716, 0.04770809, -0.3420557, 0.2208712, -0.07155832, -0.18520941, -0.28909697, -0.44532522, 0.25088246, 0.28769929, 0.49900691, 0.04533025, -0.04329381, 0.35026401, -0.25504425, 0.27891019, -0.0591087, 0.38539961, -0.4253889, 0.32590351, 0.40999293, -0.13644658, -0.12611196, 0.27326175, 0.34136452, 0.48027149, 0.442981, 0.40506636, -0.10749949, -0.09925868, 0.20118787, 0.03635117, 0.28311966, 0.20355668, -0.08541639, -0.45975, 0.38801943, -0.07863606, 0.12642975, -0.01027701, -0.28012766, -0.46840366, -0.40700885, 0.00740432, 0.17403642, -0.24551263, -0.48353639, -0.02059154, -0.37403601, 0.11663271, -0.2799406, 0.39406867, -0.46429632, 0.43165431, -0.38785408, -0.01801021, 0.32529783, -0.28043694, -0.17609873, 0.33652379, 0.29544673, -0.08367531, 0.0175073, -0.30834444, 0.49529749, -0.29489028, 0.39098276, 0.05737451, 0.0980191, 0.21655771, -0.23785685, 0.1017563, 0.21091396, -0.42097942, 0.16955045, 0.43179537, -0.05929569, -0.02390625, 0.25072136, -0.11694549, -0.24234371, -0.20645594, -0.33712536, -0.03202197, 0.32068938, -0.37179861, 0.14009284, -0.00275282, -0.03427342, 0.00967846, -0.1408125, -0.00022202]}, {'shape': [3], 'data': [0.06349408, -0.09014931, -0.13979271]}, {'shape': [3], 'data': [0.23179247, -0.08160957, 0.23309957]}, {'shape': [3], 'data': [0.35675175, -0.42538392, 0.06243438]}, {'shape': [3], 'data': [-0.34616641, -0.34524516, 0.03146308]}, {'shape': [3], 'data': [0.41538889, 0.36235194, 0.04847113]}, {'shape': [3, 3, 3, 4], 'data': [0.453838, -0.00213285, -0.16701259, -0.48209018, -0.16893152, 0.38584552, -0.01074632, 0.09650389, -0.07932097, 0.01462605, 0.17628949, 0.20195736, -0.05097213, -0.35270031, 0.46257579, 0.26689856, 0.18434048, -0.08576299, -0.39125774, 0.31994973, -0.00410204, -0.44061404, 0.00659478, -0.49405515, 0.03855197, 0.09394921, -0.24534783, 0.03991656, -0.1482182, -0.16936715, 0.40470831, -0.20560856, -0.27043351, 0.43687975, -0.01156835, 0.19314963, 0.34383263, 0.04229558, -0.40346285, -0.22739025, -0.17963078, -0.44764357, 0.16048048, 0.4092842, 0.04625274, -0.42036877, 0.37463781, 0.43789848, 0.41811209, -0.25001331, -0.06379471, -0.49448593, 0.00988367, -0.19498266, -0.17200104, -0.13528456, -0.32433989, 0.2179106, 0.06428158, -0.14300003, 0.25101403, -0.48541187, -0.30612729, -0.07498016, -0.23781245, 0.29939848, 0.49431802, 0.27695804, 0.43068463, -0.36137195, -0.41145201, 0.48895882, 0.17165577, -0.09538719, 0.14778594, -0.10919898, -0.09553142, 0.1358947, -0.1111672, 0.13066436, -0.10135252, -0.35396137, -0.06448139, 0.19562326, 0.18369471, 0.01563713, 0.31653796, -0.11380363, -0.4994088, 0.08717328, 0.34895659, -0.15875176, 0.03444962, 0.09928548, 0.27787363, -0.36716827, -0.31092127, -0.27331549, 0.27146328, -0.39557524, -0.16595417, 0.02716813, 0.18178915, 0.38373689, 0.24930402, 0.00164709, 0.33435297, 0.38462438]}, {'shape': [4], 'data': [-0.42552979, -0.42337319, -0.36113516, 0.02176155]}, {'shape': [4], 'data': [-0.20763263, 0.27821473, 0.04277914, 0.28972584]}, {'shape': [4], 'data': [0.26403048, 0.36291539, -0.18548854, 0.07559264]}, {'shape': [4], 'data': [-0.02085371, -0.24156172, 0.01700694, -0.16350372]}, {'shape': [4], 'data': [0.20293252, 0.3258068, 0.05862386, 0.42115677]}, {'shape': [3, 3, 4, 2], 'data': [0.25314372, -0.46136105, -0.17003174, -0.01427059, 0.25465141, 0.19552434, 0.45268635, 0.07641528, 0.49326056, 0.09227005, 0.12513645, 0.03517784, 0.25860935, -0.4628396, 0.07060084, 0.06899248, -0.30019978, -0.20636438, -0.37521518, -0.3175359, -0.22000664, -0.12965488, -0.0893195, 0.34638366, -0.22808845, 0.22500576, -0.33167684, -0.07065416, 0.32774902, -0.37951062, -0.20575694, -0.26086492, 0.3763493, 0.27448786, -0.19946332, -0.19001296, -0.49910124, 0.14621126, -0.38264846, -0.31286614, 0.33303078, -0.35244212, 0.29954383, -0.02865577, -0.00462185, 0.18442657, -0.04470949, 0.04702486, 0.43531818, -0.05488231, -0.00360027, 0.19172307, -0.12998845, 0.39922446, 0.33581972, 0.3759835, 0.20120504, -0.10137499, -0.0633941, -0.35050637, 0.38570233, 0.08246179, 0.0614843, 0.2840294, -0.13767422, -0.26277078, -0.2510653, 0.28337646, -0.07370449, -0.11645478, 0.40745799, 0.23625318]}, {'shape': [2], 'data': [0.31231823, 0.32132474]}, {'shape': [2], 'data': [0.36146202, 0.2630394]}, {'shape': [2], 'data': [0.18879586, 0.47586192]}, {'shape': [2], 'data': [-0.37442322, -0.25905518]}, {'shape': [2], 'data': [0.17571591, 0.09903011]}], 'expected': {'shape': [1, 1, 2], 'data': [1.83107877, 2.40030813]}}\n"
     ]
    }
   ],
   "source": [
    "data_in_shape = (24, 24, 2)\n",
    "\n",
    "conv_0 = Conv2D(5, 3, 3, activation='relu', border_mode='valid', subsample=(2, 2), dim_ordering='tf', bias=True)\n",
    "bn_0 = BatchNormalization(mode=0, axis=-1, epsilon=1e-3)\n",
    "conv_1 = Conv2D(4, 3, 3, activation='relu', border_mode='same', subsample=(1, 1), dim_ordering='tf', bias=True)\n",
    "bn_1 = BatchNormalization(mode=0, axis=-1, epsilon=1e-3)\n",
    "conv_2 = Conv2D(3, 3, 3, activation='relu', border_mode='same', subsample=(1, 1), dim_ordering='tf', bias=True)\n",
    "bn_2 = BatchNormalization(mode=0, axis=-1, epsilon=1e-3)\n",
    "pool_0 = MaxPooling2D(pool_size=(2, 2), strides=None, border_mode='valid', dim_ordering='tf')\n",
    "conv_3 = Conv2D(4, 3, 3, activation='linear', border_mode='valid', subsample=(1, 1), dim_ordering='tf', bias=True)\n",
    "bn_3 = BatchNormalization(mode=0, axis=-1, epsilon=1e-3)\n",
    "conv_4 = Conv2D(2, 3, 3, activation='relu', border_mode='same', subsample=(1, 1), dim_ordering='tf', bias=True)\n",
    "bn_4 = BatchNormalization(mode=0, axis=-1, epsilon=1e-3)\n",
    "pool_1 = MaxPooling2D(pool_size=(2, 2), strides=None, border_mode='valid', dim_ordering='tf')\n",
    "\n",
    "input_layer = Input(shape=data_in_shape)\n",
    "x = conv_0(input_layer)\n",
    "x = bn_0(x)\n",
    "x = conv_1(x)\n",
    "x = bn_1(x)\n",
    "x = conv_2(x)\n",
    "x = bn_2(x)\n",
    "x = pool_0(x)\n",
    "x = conv_3(x)\n",
    "x = bn_3(x)\n",
    "x = conv_4(x)\n",
    "x = bn_4(x)\n",
    "output_layer = pool_1(x)\n",
    "model = Model(input=input_layer, output=output_layer)\n",
    "\n",
    "np.random.seed(7000)\n",
    "data_in = 2 * np.random.random(data_in_shape) - 1\n",
    "\n",
    "# set weights to random (use seed for reproducibility)\n",
    "weights = []\n",
    "for i, w in enumerate(model.get_weights()):\n",
    "    np.random.seed(7000 + i)\n",
    "    if i % 6 == 5:\n",
    "        # std should be positive\n",
    "        weights.append(0.5 * np.random.random(w.shape))\n",
    "    else:\n",
    "        weights.append(np.random.random(w.shape) - 0.5)\n",
    "model.set_weights(weights)\n",
    "\n",
    "result = model.predict(np.array([data_in]))\n",
    "\n",
    "print({\n",
    "    'input': {'data': format_decimal(data_in.ravel().tolist()), 'shape': list(data_in_shape)},\n",
    "    'weights': [{'data': format_decimal(weights[i].ravel().tolist()), 'shape': list(weights[i].shape)} for i in range(len(weights))],\n",
    "    'expected': {'data': format_decimal(result[0].ravel().tolist()), 'shape': list(result[0].shape)}\n",
    "})"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "anaconda-cloud": {},
  "kernelspec": {
   "display_name": "Python [default]",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.5.2"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
